﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MO.ModelingClient
{
    public partial class ScriptEditForm : BaseTextEditForm
    {
        public ScriptEditForm(TreeNode[] nodes)
        {
            InitializeComponent();
            this.treeView.Nodes.AddRange(nodes);
        }

        public override void SetValue(string value)
        {
            this.richTextBox.Text = value;
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            ReturnValue(this.richTextBox.Text);
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void treeView_DoubleClick(object sender, EventArgs e)
        {
            if (treeView.SelectedNode == null)
                return;
            richTextBox.Text = richTextBox.Text.Substring(0, richTextBox.SelectionStart) + " " + treeView.SelectedNode.Tag + " " + richTextBox.Text.Substring(richTextBox.SelectionStart);
            //this.richTextBox.Text = this.richTextBox.Text.Insert(this.richTextBox.SelectionStart, treeView.SelectedNode.Tag as string);
            //treeView.SelectedNode.Tag
        }
    }
    public class SysTreeNode
    {
        public static TreeNode GetSysTreeNode()
        {
            TreeNode result = new TreeNode("系统") { Tag = "Sys" };
            TreeNode user = new TreeNode("用户") { Tag = "Sys.User" };
            user.Nodes.Add("用户编码").Tag = "Sys.User.Code";
            user.Nodes.Add("用户名称").Tag = "Sys.User.Name";
            result.Nodes.Add(user);
            result.Nodes.Add("取Guid").Tag = "Sys.Guid()";
            result.Nodes.Add("写日志").Tag = "Sys.Log(string)";
            result.Nodes.Add("添加数据").Tag = "Sys.Insert(object)";
            result.Nodes.Add("更新数据").Tag = "Sys.Update(object)";
            result.Nodes.Add("发送表单给某用户").Tag = "Sys.SendForm(userCode,formCode,DataCode)";
            result.Nodes.Add("获取实体的枚举").Tag = "Sys.FindEnum(entityCode)";
            result.ExpandAll();
            return result;
        }
    }
}
